
const App = getApp()
var businessLogic = require('../../../utils/NetWork/Model/NewsbusinessLogic.js')
var WxParse = require('../../../utils/Component/wxParse/wxParse.js');
var common = require('../../../utils/common.js')
var orgid = common.getStorageSync("orgid")
var userid = common.getStorageSync("userid")

Page({
  data: {
    itemData: [],
    itemData2: [],
    orgid: "",
    userid: "",
    school:[],
    qishcool:[]

  }, touchS: function (e) {  // touchstart
    let startX = App.Touches.getClientX(e)
    startX && this.setData({ startX })
  },
  touchM: function (e) {  // touchmove
    let itemData = App.Touches.touchM(e, this.data.itemData, this.data.startX)
    itemData && this.setData({ itemData })

  },
  touchE: function (e) {  // touchend
    const width = 150  // 定义操作列表宽度
    let itemData = App.Touches.touchE(e, this.data.itemData, this.data.startX, width)
    itemData && this.setData({ itemData })
  },
   itemDelete: function (e) {  // itemDelete
    let itemData = App.Touches.deleteItem(e, this.data.itemData)
    // console.log(e.currentTarget.dataset.hi);
    let params = { "ids": e.currentTarget.dataset.hi };
    //第三步 调用接口
    businessLogic.PeoTakeDele(params, (res) => {
    
      console.log(res);
      if (res == "成功") {
        common.showToast("取消成功", "succeed");
      } else {
        common.showToast("取消失败", "fail");
      }

    });

    itemData && this.setData({ itemData })
  }, 


    touchS1: function (e) {  // touchstart
     let startX = App.Touches.getClientX(e)
     startX && this.setData({ startX })
   },
   touchM1: function (e) {  // touchmove
     let itemData2 = App.Touches.touchM(e, this.data.itemData2, this.data.startX)
     itemData2 && this.setData({ itemData2 })

   },
   touchE1: function (e) {  // touchend
     const width = 150  // 定义操作列表宽度
     let itemData2 = App.Touches.touchE(e, this.data.itemData2, this.data.startX, width)
     itemData2 && this.setData({ itemData2 })
   },
   itemDelete2: function (e) {  // itemDelete
     let itemData2 = App.Touches.deleteItem(e, this.data.itemData2)
     // console.log(e.currentTarget.dataset.hi);
     let params = { "ids": e.currentTarget.dataset.hi };
     //第三步 调用接口
     businessLogic.PeoTakeDele(params, (res) => {
       console.log(res);
       if (res == "成功") {
         common.showToast("取消成功", "succeed");
       } else {
         common.showToast("取消失败", "fail");
       }

     });

     itemData2 && this.setData({ itemData2 })
   },

  /**
 * 生命周期函数--监听页面加载
 */

onReady: function (options) {
  this.list();
},
  onLoad: function (options) {
    this.list();
  }, 
  onShow: function (options) {
    this.list();

  }, 
  //2.1.1
  list: function () {

    var myschool = [];
    var heschool = [];

    // 第二步 传参
    let params = {
      "page": 1, "num": 1000, "orgid": orgid, "userid": userid, "searchValue": userid, "searchField": "people"
    }
    //第三步 调用接口
    businessLogic.TakeList(params, (res) => {
   
      var c = 0;
      var b = 0;
      //第五步 把获取的值，传入data
      for(var a=0;a<res.length;a++)
      {
        console.log(res[a].school);
          if(orgid==res[a].school){
            myschool[c]= res[a];
            c++;
          }else{
            heschool[b]= res[a];
            b++;
          }
      }
    
      this.setData({
        itemData: myschool,
        itemData2:heschool
      });
    });
  },
 

  // 跳转至详情页
  addOrder: function (event) {
    wx.navigateTo({
      url: "../addOrder/addOrder"
    })

  },
  orderNewsli: function (event) {
    wx.navigateTo({
      url: "../orderNewsli/orderNewsli?id=" + event.currentTarget.dataset.id
    })
  },
})